﻿using System;
using System.Windows.Forms;
using MobileCommissionManagement.Common;

namespace MobileCommissionManagement.Controls
{
    public partial class Entity : Form
    {
        private Entidades _entity;
        private int _newId = -1;

        #region Properties

        public Controller Controller
        {
            set
            {
                tiposEntidadeBindingSource.DataSource = value.EntityTypes;
                responsibleEntidadesBindingSource.DataSource = value.Entities;
                operadoresBindingSource.DataSource = value.Operators;
                zonasBindingSource.DataSource = value.Zones;
            }
        }

        public Entidades Document
        {
            set
            {
                _entity = value;
                entidadesBindingSource.DataSource = _entity;
                entidadeDetalhesBindingSource.DataSource = _entity.EntidadeDetalhes;
            }
            get { return _entity; }
        }

        #endregion

        public Entity()
        {
            InitializeComponent();
            gridView.InitNewRow += GridViewInitNewRow;
        }

        void GridViewInitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
        {
            var entityDetail = (EntidadeDetalhes)gridView.GetRow(e.RowHandle);
            entityDetail.IdEntidadeDetalhe = _newId--;
            entityDetail.DataInicio = DateTime.Now;
        }
    }
}
